
********************************************************************************
// Set macros and working directory
********************************************************************************

* Basic settings
clear all
set more off
set maxvar 32767
set matsize 11000
set seed 1
version 13

* Set working directory
cd "D:/Dropbox/Projekt/Bargaining complexity/Analys/Replication files"

* Create output directories
capture mkdir tex
capture mkdir img


********************************************************************************
// Estimate the government formation model to get the probability distribution
********************************************************************************

* Open dataset
use "Potential coalitions", replace

* Identify variables
local ivars pc_numparties pc_incparties
ds pc_*
local all = r(varlist)
local xvars : list all  - ivars
di "`xvars'"

* Variable macros
local xvars pc_conservativeseatshare pc_seatshare pc_difseatshare pc_minority pc_seatshare_sq pc_seatshare_above pc_seatshare_above_sq pc_minwin pc_leftrightrange pc_opp_leftrightrange pc_connected pc_medianparty pc_disttomedian pc_largestparty pc_singlepartymaj pc_inc pc_incpm pc_leftcab pc_populist pc_min_likedislike pc_disliked pc_tenyearparties pc_dependent pc_largedependent pc_cons_dependent pc_conservative pc_pec pc_pec_maj pc_likedislike pc_tenyear_cabdyad pc_likedislike_sq pc_parlmaj_likedislike pc_parlmaj_leftrightrange pc_minority_x_invest1_absmaj i.pc_numparties i.pc_incparties
local interactions c.pc_incparties#c.pc_numparties c.pc_likedislike#c.pc_numparties c.pc_tenyear_cabdyad#c.pc_likedislike c.pc_tenyear_cabdyad#c.pc_pec c.pc_opp_leftrightrange#c.pc_minority  c.pc_opp_leftrightrange#c.pc_connected
local smallvars pc_seatshare pc_difseatshare pc_minority pc_seatshare_above pc_minwin pc_leftrightrange pc_medianparty pc_opp_leftrightrange pc_inc pc_incpm pc_populist pc_pec 
local arithmetic i.pc_numparties i.pc_numparties pc_seatshare pc_difseatshare pc_minority pc_seatshare_sq pc_seatshare_above pc_seatshare_above_sq pc_minwin pc_largestparty pc_singlepartymaj

* Run the clogit for the full model and store the probabilities
eststo: clogit elected `xvars' `interactions', group(fo) cl(fo) difficult
predict p if e(sample)
replace p = max(0,p)

* Run the clogit for the reduced model
eststo: clogit elected i.pc_numparties i.pc_incparties `smallvars', group(fo) cl(fo) difficult
predict p_small if e(sample)
replace p_small = max(0,p_small)

* Run the clogit for model with only arithmetic variables
eststo: clogit elected `arithmetic', group(fo) cl(fo) difficult
predict p_arithmetic if e(sample)
replace p_arithmetic = max(0,p_arithmetic)

* Create Table S2: Potential government models
esttab using "tex/tab_reg.tex", replace booktabs wide label se b(2) nobaselevels ///
	eqlabels(none) mtitles("Full" "Reduced" "Arithmetic") nonotes alignment(D{.}{.}{-1}) ///
	refcat(2.pc_numparties "\emph{Number of parties}" ///
			pc_seatshare "\\\emph{Variables related to party size}" ///
			pc_leftrightrange "\\\emph{Variables related to ideology}" ///
			1.pc_incparties "\\\emph{Incumbent parties}" ///
			pc_inc "\\\emph{Other variables related to previous cooperation}" ///
			pc_pec "\\\emph{Other party characteristics}" ///
			pc_largedependent "\\\emph{Combinations of variables}", nolabel) ///
		stats(N N_clust r2_p, fmt(%7.0fc %7.0fc 2) ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "@") ///
		label("Observations" "Government formation opportunities" "Pseudo \(R^{2}\)")) ///
		order(2.pc_numparties 3.pc_numparties 4.pc_numparties 5.pc_numparties 6.pc_numparties 7.pc_numparties ///
			pc_seatshare  pc_difseatshare  pc_minority  pc_seatshare_sq  pc_seatshare_above  pc_seatshare_above_sq  pc_minwin pc_largestparty  pc_singlepartymaj ///
			 pc_leftrightrange pc_opp_leftrightrange pc_connected pc_medianparty pc_disttomedian pc_conservativeseatshare pc_conservative *pc_incparties ///
			pc_inc pc_incpm pc_leftcab pc_tenyearparties pc_tenyear_cabdyad ///
			pc_pec pc_pec_maj pc_populist pc_likedislike pc_likedislike_sq pc_min_likedislike pc_disliked pc_dependent ///
			pc_largedependent pc_cons_dependent pc_parlmaj_likedislike pc_parlmaj_leftrightrange)
filefilter "tex/tab_reg.tex" "temp.tex", replace from("{l*{3}{D{.}{.}{-1}}") to("{l*{6}{D{.}{.}{-1}}")
filefilter "temp.tex" "tex/tab_reg.tex", replace from("") to("") 
erase temp.tex
eststo clear

* Save probabilities to use in case studies
tempfile probabilities
save `probabilities'


********************************************************************************
// Calculate entropy based on the probability distribution
********************************************************************************

* Only keep the necessary variables
keep fo pc p p_arithmetic p_small
drop if p == .

* Calculate the entropy using the natural log
foreach i in main _arithmetic _small {
	if "`i'" == "main" local i = "" 
	gen ln_p`i' = ln(p`i')
	gen temp`i' = -p`i' * ln_p`i'
	bys fo: gegen entropy`i' = sum(temp`i')
}

* Only keep one observation per formation opportunity
by fo: keep if _n == 1
keep fo entropy*

* Save entropy file
tempfile entropy
save `entropy'

* Ensure that these exactly match the entropy values in the evaluation file
use "Evaluation.dta", replace
rename entropy* bk_entropy*
merge 1:1 fo using `entropy', nogen keep(1 3)
assert float(entropy) == float(bk_entropy)
assert float(entropy_small) == float(bk_entropy_small)
assert float(entropy_arithmetic) == float(bk_entropy_arithmetic)


********************************************************************************
// Descriptive table
********************************************************************************

* Write program used to create the table
capture program drop row
program define row
syntax varlist, label(string)
	su `varlist'
	local mean : di %6.2fc r(mean)
	local sd : di %6.2fc r(sd)
	local min : di %6.2fc r(min)
	local max : di %6.2fc r(max)
	local obs : di %6.0fc r(N)
	file write table "`label' & `mean' & `sd' & `min' & `max' & `obs' \\" _n
end

* Open the evaluation file
use "Evaluation.dta", replace
// keep if entropy != .

* Create binary variables for majoritarian and mixed systems
gen maj = cond(gol_est==1,1,0) if gol_est != .
gen mixed = cond(gol_est==3,1,0) if gol_est != .

* Create Table S3: Descriptive statistics
capture file close table
file open table using "tex/tab_descriptives.tex", replace write
file write table "\begin{tabular}{l*{4}{D{.}{.}{4.2}}c}" _n
file write table "\toprule" _n
file write table "&\multicolumn{1}{c}{Mean}&\multicolumn{1}{c}{SD}&\multicolumn{1}{c}{Min}&\multicolumn{1}{c}{Max}&\multicolumn{1}{c}{Obs}\\" _n
file write table "\midrule" _n
file write table "\multicolumn{6}{l}{\emph{Indicators of bargaining complexity}}\\" _n
row entropy, label(Entropy)
row parties, label(Number of parties)
row eff_numparties, label(Number of effective parties)
row bpf, label(Bargaining power fragmentation)
file write table "&&&&&\\" _n
file write table "\multicolumn{6}{l}{\emph{Determinants of bargaining complexity}}\\" _n
row maj, label("Majoritarian electoral system")
row pr, label("Proportional representation system")
row mixed, label("Mixed electoral system")
row pc_inc_maj, label("Majority-winning incumbent government")
row pc_pec_maj, label("Majority-winning PEC")
row pc_pec_min, label("Non-majority-winning PEC")
row sd_lr, label("Unweighted ideological dispersion")
row w_sd_lr, label("Seat share--weighted ideological dispersion")
file write table "&&&&&\\" _n
file write table "\multicolumn{6}{l}{\emph{Bargaining characteristics and outcomes}}\\" _n
row duration, label("Bargaining duration")
row barg_totalrounds, label("Bargaining rounds")
row barg_uniqueshare, label("Excess bargaining scope")
row cabinetduration, label("Cabinet duration")
file write table "\bottomrule" _n
file write table "\end{tabular}" _n
file close table


********************************************************************************
// Evaluate our measures
********************************************************************************

****************************************
// Bar charts
****************************************

* Open the evaluation file
use "Evaluation.dta", replace

local endash = ustrunescape("\u2013")
gcollapse (mean) entropy entropy_arithmetic entropy_small hamming, by(country)
label var entropy "Entropy"
label var entropy_small "Entropy (reduced model)"
label var entropy_arithmetic "Entropy (arithmetic model)"
label var hamming "Hamming distance"
drop if entropy == .
gsort entropy

* Figure 2: Bargaining complexity across countries
gr bar entropy, over(country,sort(entropy)lab(labsize(medsmall))) scheme(lean1) yla(,nogrid) ytitle("Mean entropy 1960`endash'2023")
capture graph export "img/barchart.pdf", as(pdf) replace

* Figure S2: Bargaining complexity across countries (reduced model)
gr bar entropy_small entropy, over(country,sort(entropy)lab(labsize(medsmall))) ///
	scheme(lean1) yla(,nogrid) ytitle("Mean entropy 1960`endash'2023") ///
	legend(lab(1 "Reduced model")lab(2 "Full model")pos(6)row(1))
capture graph export "img/barchart_small.pdf", as(pdf) replace

* Figure S3: Bargaining complexity across countries (arithmetic model)
gr bar entropy_arithmetic entropy, over(country,sort(entropy)lab(labsize(medsmall))) ///
	scheme(lean1) yla(,nogrid) ytitle("Mean entropy 1960`endash'2023") ///
	legend(lab(1 "Arithmetic model")lab(2 "Full model")pos(6)row(1))
capture graph export "img/barchart_arithmetic.pdf", as(pdf) replace


****************************************
// Country charts
****************************************

* Open the evaluation file
use "Evaluation.dta", replace

* Local prediction
levelsof country_name_short if !inlist(country_name_short,"CHE"), local(countries)
foreach c in `countries' {
	reg entropy bpf if country_name_short == "`c'"
	predict bpf2 
	
	* Case studies
	if inlist("`c'","NOR","NLD") {
		if "`c'" == "NOR" local year1 16691
		if "`c'" == "NOR" local year2 19610
		if "`c'" == "NLD" local year1 8286
		if "`c'" == "NLD" local year2 9637
		
	* Calculate coordinates of red boxes
	local xmin = `year1' - 300
	local xmax = `year2' + 300
	su entropy if inrange(electiondate,`year1',`year2') & country_name_short == "`c'"
	local ymin = r(min)
	local ymax = r(max)
	su bpf2 if inrange(electiondate,`year1',`year2') & country_name_short == "`c'"
	local ymin = min(`r(min)',`ymin') - .15
	local ymax = max(`r(max)',`ymax') + .15
	gen y1 = `ymin' if _n < 3
	gen y2 = `ymax' if _n < 3
	gen x = `xmin' if _n == 1
	replace x = `xmax' if _n == 2
	
	* Create graph for NOR/NLD
	tw 	(rbar entropy bpf2 electiondate if country_name_short == "`c'" & bpf2<entropy,lpattern(solid)lcolor("255 160 122")) ///
		(rbar entropy bpf2 electiondate if country_name_short == "`c'" & bpf2>entropy,lpattern(solid)lcolor("135 206 235")) ///
		(scatter entropy electiondate if country_name_short == "`c'",mcolor("255 160 122") msymbol(circle)) ///
		(scatter bpf2 electiondate if country_name_short == "`c'",mcolor("135 206 235") msymbol(diamond_hollow)) ///
		(function `ymax', range(`xmin' `xmax')lpattern(solid)lcolor(red)) ///
		(function `ymin', range(`xmin' `xmax')lpattern(solid)lcolor(red)) ///
		(rspike y1 y2 x,lcolor(red)), ///
		scheme(lean1) xtitle("") xla(,format(%tdCCYY)) ///
		legend(order(3 "Entropy" 4 "BPF rescaled")pos(6)row(1)) ///
		name(`c',replace) title("`c'") 

	drop y1 y2 x	
	}
	
	* Create other graphs
	else {
	tw 	(rbar entropy bpf2 electiondate if country_name_short == "`c'" & bpf2<entropy,lpattern(solid)lcolor("255 160 122")) ///
		(rbar entropy bpf2 electiondate if country_name_short == "`c'" & bpf2>entropy,lpattern(solid)lcolor("135 206 235")) ///
		(scatter entropy electiondate if country_name_short == "`c'",mcolor("255 160 122") msymbol(circle)) ///
		(scatter bpf2 electiondate if country_name_short == "`c'",mcolor("135 206 235") msymbol(diamond_hollow)), ///
		scheme(lean1) xtitle("") xla(,format(%tdCCYY)) ///
		legend(order(3 "Entropy" 4 "BPF rescaled")pos(6)row(1)) ///
		name(`c',replace) title("`c'") nodraw
	}
	
	local graphs = "`graphs'" + " `c'"
	drop bpf2
}

* Figure S1: Bargaining complexity across countries and time
gr combine `graphs', xcommon ycommon col(4) xsize(4) ysize(6) scheme(lean1)
graph export "img/country_trends_localpred.pdf", as(pdf) replace
local graphs 


****************************************
// Determinants
****************************************

* Open the evaluation file
use "Evaluation.dta", replace

* Create identicator for common sample
qui areg entropy electiondate365 parties eff_numparties bpf pc_inc_maj pc_pec distance , absorb(ccode) vce(robust) 
gen sample = e(sample)

* Table 2: Determinants of bargaining complexity
eststo: qui reg entropy ib2.gol_est electiondate365 if sample, vce(robust) 
	estadd local fixed "No" , replace
eststo: qui reg entropy ib2.gol_est electiondate365 parties eff_numparties bpf if sample, vce(robust) 
		estadd local fixed "No" , replace
eststo: qui reg entropy ib2.gol_est electiondate365 parties eff_numparties bpf pc_inc_maj pc_pec_maj pc_pec_min sd_lr w_sd_lr if sample, vce(robust) 
	estadd local fixed "No" , replace
eststo: qui areg entropy electiondate365 parties eff_numparties bpf  pc_inc_maj pc_pec_maj pc_pec_min sd_lr w_sd_lr if sample, absorb(ccode) vce(robust) 
	estadd local fixed "Yes" , replace
esttab, se ar2 star(* 0.1 ** 0.05 *** 0.01)
capture esttab using "tex/tab_determinants.tex", se ar2 star(* 0.1 ** 0.05 *** 0.01) ///
	replace booktabs nonotes label nobaselevels nomtitles nogaps ///
	alignment(D{.}{.}{3.6}) b(2) ///
	stats(N r2_a fixed, fmt(%7.0fc 2 %3.1f) ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
		label("Observations" "Adj. \(R^{2}\)" "Country FE")) 
eststo clear

* Table S4: Determinants of bargaining complexity (reduced model)
eststo: qui reg entropy_small ib2.gol_est electiondate365 if sample, vce(robust) 
	estadd local fixed "No" , replace
eststo: qui reg entropy_small ib2.gol_est electiondate365 parties eff_numparties bpf if sample, vce(robust) 
		estadd local fixed "No" , replace
eststo: qui reg entropy_small ib2.gol_est electiondate365 parties  eff_numparties bpf pc_inc_maj pc_pec_maj pc_pec_min sd_lr w_sd_lr if sample, vce(robust) 
	estadd local fixed "No" , replace
eststo: qui areg entropy_small electiondate365 parties eff_numparties bpf pc_inc_maj pc_pec_maj pc_pec_min sd_lr w_sd_lr  if sample, absorb(ccode) vce(robust) 
	estadd local fixed "Yes" , replace
esttab, se ar2 star(* 0.1 ** 0.05 *** 0.01)
capture esttab using "tex/tab_determinants_small.tex", se ar2 star(* 0.1 ** 0.05 *** 0.01) ///
	replace booktabs nonotes label nobaselevels nomtitles nogaps ///
	alignment(D{.}{.}{3.6}) b(2) ///
	stats(N r2_a fixed, fmt(%7.0fc 2 %3.1f) ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
		label("Observations" "Adj. \(R^{2}\)" "Country FE")) 
eststo clear

* Table S6: Determinants of bargaining complexity (arithmetic model)
eststo: qui reg entropy_arithmetic ib2.gol_est electiondate365 if sample, vce(robust) 
	estadd local fixed "No" , replace
eststo: qui reg entropy_arithmetic ib2.gol_est electiondate365 parties eff_numparties bpf if sample, vce(robust) 
		estadd local fixed "No" , replace
eststo: qui reg entropy_arithmetic ib2.gol_est electiondate365 parties eff_numparties bpf pc_inc_maj pc_pec_maj pc_pec_min sd_lr w_sd_lr  if sample, vce(robust) 
	estadd local fixed "No" , replace
eststo: qui areg entropy_arithmetic electiondate365 parties eff_numparties bpf pc_inc_maj pc_pec_maj pc_pec_min sd_lr w_sd_lr if sample, absorb(ccode) vce(robust) 
	estadd local fixed "Yes" , replace
esttab, se ar2 star(* 0.1 ** 0.05 *** 0.01)
capture esttab using "tex/tab_determinants_arithmetic.tex", se ar2 star(* 0.1 ** 0.05 *** 0.01) ///
	replace booktabs nonotes label nobaselevels nomtitles nogaps ///
	alignment(D{.}{.}{3.6}) b(2) ///
	stats(N r2_a fixed, fmt(%7.0fc 2 %3.1f) ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
		label("Observations" "Adj. \(R^{2}\)" "Country FE")) 
eststo clear


****************************************
// Prediction tables
****************************************

* Open the evaluation file
use "Evaluation.dta", replace

* Modify labels
label var eff_numparties "Eff. num. of parties"
label var bpf "Barg. power fragm."

* Table 5: Predicting observable bargaining characteristics and outcomes
eststo: qui reg duration entropy, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg duration entropy parties eff_numparties bpf electiondate365 i.ccode,  vce(robust)
	estadd local fixed "Yes"
	estadd ysumm
eststo: qui reg barg_totalrounds entropy, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg barg_totalrounds entropy parties eff_numparties bpf electiondate365 i.ccode, vce(robust) 
	estadd local fixed "Yes"
	estadd ysumm
eststo: qui reg barg_uniqueshare entropy, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg barg_uniqueshare entropy parties eff_numparties bpf electiondate365 i.ccode, vce(robust) 
	estadd local fixed "Yes"
	estadd ysumm
eststo: qui reg cabinetduration entropy, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg cabinetduration entropy parties eff_numparties bpf electiondate365 i.ccode, vce(robust) 
	estadd local fixed "Yes"
	estadd ysumm
esttab, se ar2 star(* 0.1 ** 0.05 *** 0.01) drop(*ccode*)
capture esttab using "tex/tab_predictions.tex", se ar2 star(* 0.1 ** 0.05 *** 0.01) ///
	replace booktabs nonotes label nobaselevels nomtitles nogaps drop(*ccode) ///
	alignment(D{.}{.}{3.6}) b(2) ///
	mgroups("Bargaining duration" "Bargaining rounds" "Excess bargaining scope" "Cabinet duration", span pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})) ///
	stats(N r2_a ymean fixed, fmt(%7.0fc 2 %4.2f) ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
		label("Observations" "Adj. \(R^{2}\)" "Outcome mean" "Country FE"))
eststo clear

* Table S5: Predicting bargaining characteristics and outcomes (reduced model)
eststo: qui reg duration entropy_small, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg duration entropy_small parties eff_numparties bpf electiondate365 i.ccode,  vce(robust)
	estadd local fixed "Yes"
	estadd ysumm
eststo: qui reg barg_totalrounds entropy_small, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg barg_totalrounds entropy_small parties eff_numparties bpf electiondate365 i.ccode, vce(robust) 
	estadd local fixed "Yes"
	estadd ysumm
eststo: qui reg barg_uniqueshare entropy_small, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg barg_uniqueshare entropy_small parties eff_numparties bpf electiondate365 i.ccode, vce(robust) 
	estadd local fixed "Yes"
	estadd ysumm
eststo: qui reg cabinetduration entropy_small, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg cabinetduration entropy_small parties eff_numparties bpf  electiondate365 i.ccode, vce(robust) 
	estadd local fixed "Yes"
	estadd ysumm
esttab, se ar2 star(* 0.1 ** 0.05 *** 0.01) drop(*ccode*)
capture esttab using "tex/tab_predictions_small.tex", se ar2 star(* 0.1 ** 0.05 *** 0.01) ///
	replace booktabs nonotes label nobaselevels nomtitles nogaps drop(*ccode) ///
	alignment(D{.}{.}{3.6}) b(2) ///
	mgroups("Bargaining duration" "Bargaining rounds" "Excess bargaining scope" "Cabinet duration", span pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})) ///
	stats(N r2_a ymean fixed, fmt(%7.0fc 2 %4.2f) ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
		label("Observations" "Adj. \(R^{2}\)" "Outcome mean" "Country FE"))
eststo clear

* Table S7: Predicting bargaining characteristics and outcomes (arithmetic model)
eststo: qui reg duration entropy_arithmetic, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg duration entropy_arithmetic parties eff_numparties bpf electiondate365 i.ccode,  vce(robust)
	estadd local fixed "Yes"
	estadd ysumm
eststo: qui reg barg_totalrounds entropy_arithmetic, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg barg_totalrounds entropy_arithmetic parties eff_numparties bpf electiondate365 i.ccode, vce(robust) 
	estadd local fixed "Yes"
	estadd ysumm
eststo: qui reg barg_uniqueshare entropy_arithmetic, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg barg_uniqueshare entropy_arithmetic parties eff_numparties bpf electiondate365 i.ccode, vce(robust) 
	estadd local fixed "Yes"
	estadd ysumm
eststo: qui reg cabinetduration entropy_arithmetic, vce(robust) 
	estadd local fixed "No"
	estadd ysumm
eststo: qui reg cabinetduration entropy_arithmetic parties eff_numparties bpf  electiondate365 i.ccode, vce(robust) 
	estadd local fixed "Yes"
	estadd ysumm
esttab, se ar2 star(* 0.1 ** 0.05 *** 0.01) drop(*ccode*)
capture esttab using "tex/tab_predictions_arihmetic.tex", se ar2 star(* 0.1 ** 0.05 *** 0.01) ///
	replace booktabs nonotes label nobaselevels nomtitles nogaps drop(*ccode) ///
	alignment(D{.}{.}{3.6}) b(2) ///
	mgroups("Bargaining duration" "Bargaining rounds" "Excess bargaining scope" "Cabinet duration", span pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})) ///
	stats(N r2_a ymean fixed, fmt(%7.0fc 2 %4.2f) ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
		label("Observations" "Adj. \(R^{2}\)" "Outcome mean" "Country FE"))
eststo clear


****************************************
// Comparison of predictive capacity across outcomesa and measures
****************************************

* Open the evaluation file
use "Evaluation.dta", replace

* Labels for the different measures
gen var = ""
replace var = "Entropy" if _n == 1
replace var = "Entropy (arithmetic model)" if _n == 2
replace var = "Entropy (reduced model)" if _n == 3
replace var = "Laver & Benoit (2015)" if _n == 4
replace var = "Bargaining power fragmentation" if _n == 5
replace var = "Effective number of parties" if _n == 6
replace var = "Number of parties" if _n == 7

foreach v in duration barg_totalrounds barg_uniqueshare cabinetduration {
gen ar2_`v' = .
reg `v'  entropy 
replace ar2_`v' = e(r2_a) if _n == 1
reg `v'  entropy_arithmetic
replace ar2_`v' = e(r2_a) if _n == 2
reg `v'  entropy_small
replace ar2_`v' = e(r2_a) if _n == 3
reg `v'  i.lb15 
replace ar2_`v' = e(r2_a) if _n == 4
reg `v'  bpf 
replace ar2_`v' = e(r2_a) if _n == 5
reg `v'  eff_numparties 
replace ar2_`v' = e(r2_a) if _n == 6
reg `v'  parties
replace ar2_`v' = e(r2_a) if _n == 7
}
gen order = _n

* Figure S4: Comparison of predictive capacity across outcomes and measures
gr bar ar2_duration ar2_barg_totalrounds ar2_barg_uniqueshare ar2_cabinetduration, over(var,sort(order) label(labsize(vsmall))) horizontal ///
	scheme(s1mono) yla(0 .1 .2,nogrid labsize(vsmall)) plotregion(margin(l=0)) graphregion(margin(2 0.1 0.1 0.1)) xsize(5) ysize(4) ///
	bar(1,color(gs6)) bar(2,color(gs12)) bar(3,color(gs9)) yscale(r(0 .21)) ///
	legend(col(2)bmargin(zero)keygap(0.5) colgap(2) ///
	label(1 "Bargaining duration")label(2 "Bargaining rounds")label(3 "Excess bargaining scope") label(4 "Cabinet duration") region(style(none))size(vsmall)symxsize(3)margin(zero)) 
graph export "img/adjr2_comparison.pdf", as(pdf) replace


****************************************
// Case studies
****************************************

* Open the evaluation file
use "Evaluation.dta", replace

sort electiondate
list fo cabinet_name eff_nu bpf entropy entropy_arithmetic duration barg_fail_rounds barg_losers if inlist(cabinet_name,"Lubbers I","Lubbers II")
list fo cabinet_name eff_nu bpf entropy entropy_arithmetic duration barg_fail_rounds barg_losers if inlist(cabinet_name,"Stoltenberg II","Solberg I")

use "Potential coalitions.dta", clear
merge 1:1 fo pc using `probabilities', nogen keep(1 3)
gsort fo -p
by fo: gen rank = _n
* Lubbers I
list fo cabnumstring p if rank < 4 & fo == 270
* Lubbers II
list fo cabnumstring p if rank < 4 & fo == 550
* Stoltenberg II
list fo cabnumstring p if rank < 4 & fo == 693
* Solberg I
list fo cabnumstring p if rank < 4 & fo == 1065


